// --------------------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------------------
// behaviours - manages tool tip display in forms;
// depends: 	jQuery library;
// author:		mdja;
// --------------------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------------------


// -- define namespace;
if (typeof Compare !== 'object') var Compare={};

// -- define card selector object;
Compare.toolTipManager = new (function(){
	// private members;
	var row_array = [];
	var current_row = null;
	var me = this;
	
	// private methods;
	var bindRowEvents = function(row_el, index) {
		
		row_array.push(row_el);
		if (!$(row_el).hasClass('showToolTip'))
			$(row_el).find('input, textarea, select').
				mouseover(function() {me.onRowFocus(index);}).blur(function() {me.onRowBlur(index);})
				// focus(function() {me.onRowFocus(index);}).blur(function() {me.onRowBlur(index);})
				.end().find('a.showCallout').
				click(function() {me.onRowFocus(index, this); return false;});
	};
	
	// public methods;
	this.onReady = function() {
		// obtain all form field rows;
		var form_row_els = $('#contentBody div.section div.row');
		for (var i = 0, l = form_row_els.length; i < l; i++) 
				bindRowEvents(form_row_els[i], i);	
	};
	
	this.onRowFocus = function(index, align_with) {
		if (current_row!=null) $(row_array[current_row]).removeClass('showToolTip');
		$(row_array[index]).addClass('showToolTip');
		current_row = index;
		// position;
		if (align_with) $(row_array[index]).find('div.callout').css({top: (align_with.offsetTop - 24)});
	};
	
	this.onRowBlur = function(index) {
	};
	
});

$(document).ready(function(){Compare.toolTipManager.onReady();});

// --------------------------------------------------------------------------------------------------------------------------------
// --- end of file --- 
// -------------------------------------------------------------------------------------------------------------------------------
